<?php
/*
 * This file is part of the BooXtore Student project.
 *
 * (c) Francis Backeland f.backeland@gmail.com
 * (c) Laurine Chaplot chaplot.laurine@orange.fr
 * (c) Julien Dutot julien.dutot@gmail.com
 * (c) Romain Guillaume romain-guillaume@orange.fr
 * (c) Guillaume Paringaux g.paringaux@gmail.com
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code
 */
namespace BXTR\LayoutBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\Options;
/** 
 * Icon submit Form Type
 * Simple submit button with a bootstrap glyphicon.
 * The name of the icon is provided in the icon option.
 * If the 'datatables_selector' option is set to true, the button will be able to select rows on
 * a datatable in the same form.
 *
 * The view is defined in BXTRLayoutBundle:Form:fields-bootstrap.html.twig
 */
class IconButtonType extends SubmitType
{
    /** 
     * Form clean name : icon_button
     */
    public function getName()
    {
        return 'icon_button';
    }

    /**
     * Extends the submit FormType
     */
    public function getParent()
    {
        return 'submit';
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'icon' => null,
            'datatables_selector' => false,
        ));
    }

    /**
     * Add the icon_class vars to the views
     *
     * @param FormView $view
     * @param FormInterface $form
     * @param Array $options
     */
    public function buildView(FormView $view, FormInterface $form, Array $options)
    {
        // The display is handled directly on the button_widget redifinition in the file 
        // BXTRLayoutBundle:Form:fields-bootstrap.html.twig
        $view->vars['icon_class'] = $options['icon'];
        $view->vars['is_datatables_selector'] = $options['datatables_selector'];
    }


}
